home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue51 / SafeCall / ComServer_TLB.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-08-19  |  9.8 KB  |  286 lines

  1. unit ComServer_TLB;
  2.  
  3. // ************************************************************************ //
  4. // WARNING                                                                    
  5. // -------                                                                    
  6. // The types declared in this file were generated from data read from a       
  7. // Type Library. If this type library is explicitly or indirectly (via        
  8. // another type library referring to this type library) re-imported, or the   
  9. // 'Refresh' command of the Type Library Editor activated while editing the   
  10. // Type Library, the contents of this file will be regenerated and all        
  11. // manual modifications will be lost.                                         
  12. // ************************************************************************ //
  13.  
  14. // PASTLWTR : $Revision:   1.88  $
  15. // File generated on 19/08/99 17:58:31 from Type Library described below.
  16.  
  17. // *************************************************************************//
  18. // NOTE:                                                                      
  19. // Items guarded by $IFDEF_LIVE_SERVER_AT_DESIGN_TIME are used by properties  
  20. // which return objects that may need to be explicitly created via a function 
  21. // call prior to any access via the property. These items have been disabled  
  22. // in order to prevent accidental use from within the object inspector. You   
  23. // may enable them by defining LIVE_SERVER_AT_DESIGN_TIME or by selectively   
  24. // removing them from the $IFDEF blocks. However, such items must still be    
  25. // programmatically created via a method of the appropriate CoClass before    
  26. // they can be used.                                                          
  27. // ************************************************************************ //
  28. // Type Lib: D:\Magazines\Work In Progress\52 - Dec 99\Safecall\Files\ComServer.tlb (1)
  29. // IID\LCID: {8DD636AC-5643-11D3-96EC-0060978E1359}\0
  30. // Helpfile: 
  31. // DepndLst: 
  32. //   (1) v2.0 stdole, (C:\WINDOWS\SYSTEM\STDOLE2.TLB)
  33. //   (2) v4.0 StdVCL, (C:\WINDOWS\SYSTEM\STDVCL40.DLL)
  34. // ************************************************************************ //
  35. {$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers. 
  36. interface
  37.  
  38. uses Windows, ActiveX, Classes, Graphics, OleServer, OleCtrls, StdVCL;
  39.  
  40. // *********************************************************************//
  41. // GUIDS declared in the TypeLibrary. Following prefixes are used:        
  42. //   Type Libraries     : LIBID_xxxx                                      
  43. //   CoClasses          : CLASS_xxxx                                      
  44. //   DISPInterfaces     : DIID_xxxx                                       
  45. //   Non-DISP interfaces: IID_xxxx                                        
  46. // *********************************************************************//
  47. const
  48.   // TypeLibrary Major and minor versions
  49.   ComServerMajorVersion = 1;
  50.   ComServerMinorVersion = 0;
  51.  
  52.   LIBID_ComServer: TGUID = '{8DD636AC-5643-11D3-96EC-0060978E1359}';
  53.  
  54.   IID_IErrorTrappingTest: TGUID = '{8DD636AD-5643-11D3-96EC-0060978E1359}';
  55.   CLASS_ErrorTrappingTest: TGUID = '{8DD636AF-5643-11D3-96EC-0060978E1359}';
  56. type
  57.  
  58. // *********************************************************************//
  59. // Forward declaration of types defined in TypeLibrary                    
  60. // *********************************************************************//
  61.   IErrorTrappingTest = interface;
  62.  
  63. // *********************************************************************//
  64. // Declaration of CoClasses defined in Type Library                       
  65. // (NOTE: Here we map each CoClass to its Default Interface)              
  66. // *********************************************************************//
  67.   ErrorTrappingTest = IErrorTrappingTest;
  68.  
  69.  
  70. // *********************************************************************//
  71. // Interface: IErrorTrappingTest
  72. // Flags:     (256) OleAutomation
  73. // GUID:      {8DD636AD-5643-11D3-96EC-0060978E1359}
  74. // *********************************************************************//
  75.   IErrorTrappingTest = interface(IUnknown)
  76.     ['{8DD636AD-5643-11D3-96EC-0060978E1359}']
  77.     procedure Error1; safecall;
  78.     procedure Error2; safecall;
  79.     procedure Error3; safecall;
  80.     procedure Error4; safecall;
  81.     procedure Error5; safecall;
  82.   end;
  83.  
  84. // *********************************************************************//
  85. // The Class CoErrorTrappingTest provides a Create and CreateRemote method to          
  86. // create instances of the default interface IErrorTrappingTest exposed by              
  87. // the CoClass ErrorTrappingTest. The functions are intended to be used by             
  88. // clients wishing to automate the CoClass objects exposed by the         
  89. // server of this typelibrary.                                            
  90. // *********************************************************************//
  91.   CoErrorTrappingTest = class
  92.     class function Create: IErrorTrappingTest;
  93.     class function CreateRemote(const MachineName: string): IErrorTrappingTest;
  94.   end;
  95.  
  96.  
  97. // *********************************************************************//
  98. // OLE Server Proxy class declaration
  99. // Server Object    : TErrorTrappingTest
  100. // Help String      : ErrorTrappingTest Object
  101. // Default Interface: IErrorTrappingTest
  102. // Def. Intf. DISP? : No
  103. // Event   Interface: 
  104. // TypeFlags        : (2) CanCreate
  105. // *********************************************************************//
  106. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  107.   TErrorTrappingTestProperties= class;
  108. {$ENDIF}
  109.   TErrorTrappingTest = class(TOleServer)
  110.   private
  111.     FIntf:        IErrorTrappingTest;
  112. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  113.     FProps:       TErrorTrappingTestProperties;
  114.     function      GetServerProperties: TErrorTrappingTestProperties;
  115. {$ENDIF}
  116.     function      GetDefaultInterface: IErrorTrappingTest;
  117.   protected
  118.     procedure InitServerData; override;
  119.   public
  120.     constructor Create(AOwner: TComponent); override;
  121.     destructor  Destroy; override;
  122.     procedure Connect; override;
  123.     procedure ConnectTo(svrIntf: IErrorTrappingTest);
  124.     procedure Disconnect; override;
  125.     procedure Error1;
  126.     procedure Error2;
  127.     procedure Error3;
  128.     procedure Error4;
  129.     procedure Error5;
  130.     property  DefaultInterface: IErrorTrappingTest read GetDefaultInterface;
  131.   published
  132. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  133.     property Server: TErrorTrappingTestProperties read GetServerProperties;
  134. {$ENDIF}
  135.   end;
  136.  
  137. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  138. // *********************************************************************//
  139. // OLE Server Properties Proxy Class
  140. // Server Object    : TErrorTrappingTest
  141. // (This object is used by the IDE's Property Inspector to allow editing
  142. //  of the properties of this server)
  143. // *********************************************************************//
  144.  TErrorTrappingTestProperties = class(TPersistent)
  145.   private
  146.     FServer:    TErrorTrappingTest;
  147.     function    GetDefaultInterface: IErrorTrappingTest;
  148.     constructor Create(AServer: TErrorTrappingTest);
  149.   protected
  150.   public
  151.     property DefaultInterface: IErrorTrappingTest read GetDefaultInterface;
  152.   published
  153.   end;
  154. {$ENDIF}
  155.  
  156.  
  157. procedure Register;
  158.  
  159. implementation
  160.  
  161. uses ComObj;
  162.  
  163. class function CoErrorTrappingTest.Create: IErrorTrappingTest;
  164. begin
  165.   Result := CreateComObject(CLASS_ErrorTrappingTest) as IErrorTrappingTest;
  166. end;
  167.  
  168. class function CoErrorTrappingTest.CreateRemote(const MachineName: string): IErrorTrappingTest;
  169. begin
  170.   Result := CreateRemoteComObject(MachineName, CLASS_ErrorTrappingTest) as IErrorTrappingTest;
  171. end;
  172.  
  173. procedure TErrorTrappingTest.InitServerData;
  174. const
  175.   CServerData: TServerData = (
  176.     ClassID:   '{8DD636AF-5643-11D3-96EC-0060978E1359}';
  177.     IntfIID:   '{8DD636AD-5643-11D3-96EC-0060978E1359}';
  178.     EventIID:  '';
  179.     LicenseKey: nil;
  180.     Version: 500);
  181. begin
  182.   ServerData := @CServerData;
  183. end;
  184.  
  185. procedure TErrorTrappingTest.Connect;
  186. var
  187.   punk: IUnknown;
  188. begin
  189.   if FIntf = nil then
  190.   begin
  191.     punk := GetServer;
  192.     Fintf:= punk as IErrorTrappingTest;
  193.   end;
  194. end;
  195.  
  196. procedure TErrorTrappingTest.ConnectTo(svrIntf: IErrorTrappingTest);
  197. begin
  198.   Disconnect;
  199.   FIntf := svrIntf;
  200. end;
  201.  
  202. procedure TErrorTrappingTest.DisConnect;
  203. begin
  204.   if Fintf <> nil then
  205.   begin
  206.     FIntf := nil;
  207.   end;
  208. end;
  209.  
  210. function TErrorTrappingTest.GetDefaultInterface: IErrorTrappingTest;
  211. begin
  212.   if FIntf = nil then
  213.     Connect;
  214.   Assert(FIntf <> nil, 'DefaultInterface is NULL. Component is not connected to Server. You must call ''Connect'' or ''ConnectTo'' before this operation');
  215.   Result := FIntf;
  216. end;
  217.  
  218. constructor TErrorTrappingTest.Create(AOwner: TComponent);
  219. begin
  220.   inherited Create(AOwner);
  221. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  222.   FProps := TErrorTrappingTestProperties.Create(Self);
  223. {$ENDIF}
  224. end;
  225.  
  226. destructor TErrorTrappingTest.Destroy;
  227. begin
  228. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  229.   FProps.Free;
  230. {$ENDIF}
  231.   inherited Destroy;
  232. end;
  233.  
  234. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  235. function TErrorTrappingTest.GetServerProperties: TErrorTrappingTestProperties;
  236. begin
  237.   Result := FProps;
  238. end;
  239. {$ENDIF}
  240.  
  241. procedure TErrorTrappingTest.Error1;
  242. begin
  243.   DefaultInterface.Error1;
  244. end;
  245.  
  246. procedure TErrorTrappingTest.Error2;
  247. begin
  248.   DefaultInterface.Error2;
  249. end;
  250.  
  251. procedure TErrorTrappingTest.Error3;
  252. begin
  253.   DefaultInterface.Error3;
  254. end;
  255.  
  256. procedure TErrorTrappingTest.Error4;
  257. begin
  258.   DefaultInterface.Error4;
  259. end;
  260.  
  261. procedure TErrorTrappingTest.Error5;
  262. begin
  263.   DefaultInterface.Error5;
  264. end;
  265.  
  266. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  267. constructor TErrorTrappingTestProperties.Create(AServer: TErrorTrappingTest);
  268. begin
  269.   inherited Create;
  270.   FServer := AServer;
  271. end;
  272.  
  273. function TErrorTrappingTestProperties.GetDefaultInterface: IErrorTrappingTest;
  274. begin
  275.   Result := FServer.DefaultInterface;
  276. end;
  277.  
  278. {$ENDIF}
  279.  
  280. procedure Register;
  281. begin
  282.   RegisterComponents('Servers',[TErrorTrappingTest]);
  283. end;
  284.  
  285. end.
  286.